residence <-
  data_1 %>%
  filter(abs(forcing_skd) < 5) %>%
  group_by(quintile_relg_diff_residence) %>%
  do(tidy(lm_robust(religious_index_skd_bw_1 ~ fail_skd, data = .))) %>%
  filter(term == "fail_skd", !is.na(quintile_relg_diff_residence)) %>%
  mutate(type = "By Place of Residence") %>%
  rename(quintile = quintile_relg_diff_residence)

job_loc <-
  data_1 %>%
  filter(abs(forcing_skd) < 5) %>%
  group_by(quintile_relg_diff_job_loc) %>%
  do(tidy(lm_robust(religious_index_skd_bw_1 ~ fail_skd, data = .))) %>%
  filter(term == "fail_skd", !is.na(quintile_relg_diff_job_loc)) %>%
  mutate(type = "By Job Location") %>%
  rename(quintile = quintile_relg_diff_job_loc)


relg_sensitivity <-
  bind_rows(residence, job_loc) %>%
  mutate(quintile = factor(quintile, levels = c("[0, 3.7)","[3.7, 6.9)",  "[6.9,10.9)", "[10.9,17.5)", "[17.5,66.1)",
                                                "[0, 3.8)", "[3.8, 7.4)", "[7.4,10.7)", "[10.7,15.2)", "[15.2,66.8)"))) %>%
  ggplot(aes(x=quintile, y = estimate)) +
  geom_errorbar(aes(ymin = estimate - 1.68*std.error, ymax = estimate + 1.68*std.error), size = 0.8, width = 0) +
  geom_errorbar(aes(ymin = estimate - 1.96*std.error, ymax = estimate + 1.96*std.error), size = 0.4, width = 0) +
  geom_point() +
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_bw() +
  theme(panel.grid.minor = element_blank(), 
        panel.grid.major.x = element_blank(),
        axis.line.y.left = element_blank(),
        axis.line = element_line(colour = "black"),
        panel.border = element_blank(),
        strip.background = element_blank(),
        legend.title = element_blank()) +
  facet_wrap(type ~ ., scales = "free_x") +
  #scale_color_manual(labels = c("passed", "failed"), values = c("darkgrey", "#756bb1")) +
  ylab("Religious Intolerance Index (SDs)") +
  xlab("Average Absolute Religious Group Score Difference, District Quintiles") +
  theme(text=element_text(size=10))


ggsave(filename = "./_4_outputs/figures/figure_4.pdf", plot = relg_sensitivity, width = 7, height = 3)



